package com.guyj.baseapp.demo.okhttputils;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.guyj.baseapp.R;
import com.guyj.common.base.BaseActivity;
import com.guyj.common.entity.RegisterUuid4AppBean;
import com.guyj.common.http.HttpUtils;
import com.guyj.common.http.ResultCallback;
import com.guyj.common.utils.LogUtils;

import butterknife.Bind;
import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 *  compile 'com.lzy.net:okhttputils:1.8.1'
 *  缓存与网络请求接口已分开 请求结束方法也只执行一次 具体调用顺序参考类AbsCallback<T>
 */
public class HttpDemoActivity extends BaseActivity {

    @Bind(R.id.tv_http_status)
    TextView tvHttpStatus;

    @Override
    public int getContentViewId() {
        return R.layout.activity_http_demo;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setBack();
        setTitle("OkHttpUtils by lzy");
    }

    @Override
    protected void initVariable() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        getTokenFromHttp();
    }

    private void getTokenFromHttp() {
        initProgressDialog();
        tvHttpStatus.setText("加载中...");
        HttpUtils.registerUuid4App("123456", new ResultCallback<RegisterUuid4AppBean>() {
            @Override
            public void onAfter(@Nullable RegisterUuid4AppBean registerUuid4AppBean, @Nullable Exception e) {
                dismissProgressDialog();
            }

            @Override
            public void onCacheSuccess(RegisterUuid4AppBean registerUuid4AppBean, Call call) {
                LogUtils.d("http","onCacheSuccess");
                tvHttpStatus.setText("onCacheSuccess...");
            }

            @Override
            public void onSuccess(RegisterUuid4AppBean registerUuid4AppBean, Call call, Response response) {
                LogUtils.d("http","onSuccess");
                tvHttpStatus.setText("onSuccess...");
            }

        });
    }
}
